package com.dlnu.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.dlnu.bean.Absence;
import com.dlnu.mapper.AbsenceMapper;
import com.dlnu.service.AbsenceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

@Service
public class AbsenceServiceImpl implements AbsenceService {
    @Autowired
    private AbsenceMapper absenceMapper;

    @Override
    public int create(Absence absence) {
        return absenceMapper.create(absence);
    }

    @Override
    public int delete(String ids) {
        String[] arr = ids.split(",");
        int row = 0;
        for (String s : arr) {
            if(!StringUtils.isEmpty(s)){
                absenceMapper.delete(Integer.parseInt(s));
                row++;
            }
        }
        return row;
    }

    @Override
    public int delete(Integer id) {
        return absenceMapper.delete(id);
    }

    @Override
    public int update(Absence absence) {
        return absenceMapper.update(absence);
    }

    @Override
    public int updateSelective(Absence absence) {
        return absenceMapper.updateSelective(absence);
    }

    @Override
    public PageInfo<Absence> query(Absence absence) {
        if(absence != null && absence.getPage() != null){
            PageHelper.startPage(absence.getPage(),absence.getLimit());
        }
        return new PageInfo<Absence>(absenceMapper.query(absence));
    }

    @Override
    public Absence detail(Integer id) {
        return absenceMapper.detail(id);
    }

    @Override
    public int count(Absence absence) {
        return absenceMapper.count(absence);
    }
}
